package sk.ogame.realm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import sk.ogame.realm.entity.Star;
import sk.ogame.realm.service.StarService;

import java.util.List;

/**
 * @author 支绍昆
 * 2023/2/2
 **/
@RequestMapping("/star")
@Controller
public class StarController {

    @Autowired
    private StarService starService;

    @GetMapping
    public String star(Model model){
        List<Star> starList = starService.listAll();
        model.addAttribute("starList", starList);
        return "star";
    }

    @PostMapping(value = "/add")
    public String add(@ModelAttribute Star star){
        starService.add(star);
        return "redirect:/star";
    }

    @ResponseBody
    @PostMapping(value = "/del")
    public String del(String id){
        int del = starService.del(Integer.parseInt(id));
        return String.valueOf(del);
    }
}
